//
//  TabManager.h
//  CLBrowser
//
//  Created by 梁慧聪 on 21/7/30.
//  Copyright © 2021年 梁慧聪. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CLWebContainerView.h"
#import "CLWebViewBridge.h"
@class CLWebModel, CLSessionData;

typedef void(^MultiWebViewOperationBlock)(NSArray<CLWebModel *> *);
typedef void(^CurWebViewOperationBlock)(CLWebModel *, CLWebView *);
typedef void(^CLBrowserNoParamsBlock)(void);
typedef void(^SwitchOperationBlock)(CLWebModel *preWebModel, CLWebModel *curWebModel);

@interface CLWebModel : NSObject <NSSecureCoding>

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *url;
@property (nonatomic, copy) NSString *imageKey;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) CLWebView *webView;
@property (nonatomic, assign) BOOL isImageProcessed;
@property (nonatomic, strong) CLSessionData *sessionData;
@end

@class CLWebView;

@interface CLWebViewManager : NSObject

@property (nonatomic, weak) CLWebContainerView *clContainerView;

SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(CLWebViewManager);

- (void)setMultiWebViewOperationBlockWith:(MultiWebViewOperationBlock)block;
- (void)setCurWebViewOperationBlockWith:(CurWebViewOperationBlock)block;
- (void)switchToLeftWindowWithCompletion:(SwitchOperationBlock)block;
- (void)switchToRightWindowWithCompletion:(SwitchOperationBlock)block;
- (void)updateWebModelArray:(NSArray<CLWebModel *> *)webArray;
- (void)updateWebModelArray:(NSArray<CLWebModel *> *)webArray completion:(CLBrowserNoParamsBlock)block;
- (void)addWebModelWithURL:(NSURL *)url completion:(CLBrowserNoParamsBlock)completion;
- (void)saveWebModelData;
- (CLWebModel *)getCurrentWebModel;
- (BOOL)isCurrentWebView:(CLWebView *)webView;
- (void)stopLoadingCurrentWebView;
- (NSUInteger)numberOfTabs;
- (CLWebModel *)getDefaultWebModel;
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
@end
